Unveiling the Ticket Price Dynamics: A Deep Dive
into Tomaticket’s Show Prices
Andrea Baños and Daniel Pérez
2024-03-10
Main libraries
library(rvest)
library(xml2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ readr::guess_encoding() masks rvest::guess_encoding()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
Load data from the Tomaticket website
url <- "https://www.tomaticket.es/index.php?accion=search&buscador=&IdLugar=0&IdTag=4"
tomaticket <- read_html(url) |> xml_child()
tomaticket
## {html_node}
## <head>
## [1] <script>\n\t(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n ...
## [2] <link href="https://static.tomaticket.es" rel="preconnect">\n
## [3] <meta name="ahrefs-site-verification" content="345b57ddbea35e72b0feece7f ...
## [4] <meta name="norton-safeweb-site-verification" content="is1-2cdujg6d8m6c4 ...
## [5] <meta name="wot-verification" content="29c7f69c29090c6bf37d">\n
## [6] <meta name="ir-site-verification-token" value="-601912225">\n
## [7] <meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n
## [8] <meta name="dc.language" content="es">\n
## [9] <meta property="og:title" content="Resultados de la búsqueda: ">\n
## [10] <meta property="og:locale" content="es_ES">\n
## [11] <meta property="og:url" content="https://www.tomaticket.es/index.php?acc ...
## [12] <meta property="og:type" content="website">\n
## [13] <meta property="og:site_name" content="TomaTicket">\n
## [14] <title>Resultados de la búsqueda: </title>\n
## [15] <meta name="dcterms.title" content="Resultados de la búsqueda: ">\n
## [16] <meta name="Description" content="Crea eventos fácilmente con TomaTicket ...
## [17] <meta property="og:image" content="https://static.tomaticket.es/img/logo ...
## [18] <meta name="viewport" content="width=device-width, initial-scale=1, user ...
## [19] <link rel="search" type="application/opensearchdescription+xml" href="// ...
## [20] <link rel="shortcut icon" type="image/x-icon" href="//static.tomaticket. ...
## ...
urls_clean <- show[!grepl("^https:", show)]
show_links <- paste0("https://www.tomaticket.es/", urls_clean)
show_links
## [1] "https://www.tomaticket.es//es-es/entradas-doble-o-nada-madrid"
## [2] "https://www.tomaticket.es//es-es/entradas-yo-sobrevivi-a-la-egb-en-barcelona"
## [3] "https://www.tomaticket.es//es-es/entradas-magia-de-cerca-en-madrid"
## [4] "https://www.tomaticket.es//es-es/entradas-corta-cable-rojo-madrid"
## [5] "https://www.tomaticket.es//es-es/entradas-imposible-javier-luxor-en-madrid"
## [6] "https://www.tomaticket.es//es-es/entradas-la-mama-en-madrid"
## [7] "https://www.tomaticket.es//es-es/entradas-david-guapo-madrid"
## [8] "https://www.tomaticket.es//es-es/entradas-la-azotea-madrid"
## [9] "https://www.tomaticket.es//es-es/entradas-alex-clavero-en-madrid"
## [10] "https://www.tomaticket.es//es-es/entradas-fan-madrid"
## [11] "https://www.tomaticket.es//es-es/entradas-una-terapia-integral-en-madrid"
## [12] "https://www.tomaticket.es//es-es/entradas-aqui-estoy-en-barcelona"
## [13] "https://www.tomaticket.es//es-es/entradas-el-nombre-en-madrid"
## [14] "https://www.tomaticket.es//es-es/entradas-los-locos-de-la-impro-con-andreu-casanova-en-madrid"
## [15] "https://www.tomaticket.es//es-es/entradas-lotto-en-madrid"
## [16] "https://www.tomaticket.es//es-es/entradas-fuego-salvaje-en-madrid"
## [17] "https://www.tomaticket.es//es-es/entradas-la-hora-y-media-de-el-club-de-la-comedia-valladolid"
## [18] "https://www.tomaticket.es//es-es/entradas-el-darrer-harrington-en-barcelona"
## [19] "https://www.tomaticket.es//es-es/entradas-alicia-en-el-pais-de-las-maravillas-en-madrid"
## [20] "https://www.tomaticket.es//es-es/entradas-tiquismiquis-en-madrid"
## [21] "https://www.tomaticket.es//es-es/entradas-vive-moliere-en-madrid"
## [22] "https://www.tomaticket.es//es-es/entradas-obscena-familiar-en-barcelona"
## [23] "https://www.tomaticket.es//es-es/entradas-lilla-deserta-en-barcelona"
## [24] "https://www.tomaticket.es//es-es/entradas-madres-en-madrid"
## [25] "https://www.tomaticket.es//es-es/entradas-el-anticoach-con-pablo-chiapella-funcion-especial-en-madrid"
## [26] "https://www.tomaticket.es//es-es/entradas-trash-yllana-en-madrid"
## [27] "https://www.tomaticket.es//es-es/entradas-entrevista-en-madrid"
## [28] "https://www.tomaticket.es//es-es/entradas-pareja-abierta-en-madrid"
## [29] "https://www.tomaticket.es//es-es/entradas-aqui-y-ahora-monologo-comico-terapeutico-en-barcelona"
## [30] "https://www.tomaticket.es//es-es/entradas-lo-positivo-de-fracasar-en-madrid"
## [31] "https://www.tomaticket.es//es-es/entradas-magia-a-saco-en-madrid"
## [32] "https://www.tomaticket.es//es-es/entradas-fiesta-en-la-granja-en-madrid"
## [33] "https://www.tomaticket.es//es-es/entradas-una-rana-y-los-dinos-en-madrid"
## [34] "https://www.tomaticket.es//es-es/entradas-la-magia-esta-en-ti-en-madrid"
## [35] "https://www.tomaticket.es//es-es/entradas-una-rana-en-el-mar-en-madrid"
## [36] "https://www.tomaticket.es//es-es/entradas-tarari-y-tantan-buscando-la-luna-en-madrid"
## [37] "https://www.tomaticket.es//es-es/entradas-princesa-20-en-madrid"
## [38] "https://www.tomaticket.es//es-es/entradas-Javi-rufo-madrid"
## [39] "https://www.tomaticket.es//es-es/entradas-fugaz-por-javier-luxor-en-madrid"
## [40] "https://www.tomaticket.es//es-es/entradas-un-secreto-a-voces-en-madrid"
## [41] "https://www.tomaticket.es//es-es/entradas-hector-hurien-mitos-griegos-madrid"
## [42] "https://www.tomaticket.es//es-es/entradas-ultrashow-madrid"
## [43] "https://www.tomaticket.es//es-es/entradas-alacasin-en-madrid"
## [44] "https://www.tomaticket.es//es-es/entradas-fabulosas-travesuras-en-madrid"
## [45] "https://www.tomaticket.es//es-es/entradas-la-herencia-en-madrid"
## [46] "https://www.tomaticket.es//es-es/entradas-teo-y-noa-al-rescate-en-madrid"
## [47] "https://www.tomaticket.es//es-es/entradas-magia-de-cercamuy-de-cerca-en-madrid"
## [48] "https://www.tomaticket.es//es-es/entradas-felipe-v-el-rey-que-nos-salio-rana-en-madrid"
## [49] "https://www.tomaticket.es//es-es/entradas-cadiz-madrid"
## [50] "https://www.tomaticket.es//es-es/entradas-hostia-patxi-en-madrid"
## [51] "https://www.tomaticket.es//es-es/entradas-tributo-lina-morgan-madrid"
## [52] "https://www.tomaticket.es//es-es/entradas-miguel-lago-madrid"
## [53] "https://www.tomaticket.es//es-es/entradas-chas-y-de-repente-tu-en-madrid"
## [54] "https://www.tomaticket.es//es-es/entradas-la-madre-que-me-pario-en-madrid"
## [55] "https://www.tomaticket.es//es-es/entradas-forever-van-gogh-madrid"
## [56] "https://www.tomaticket.es//es-es/entradas-la-farsa-del-siglo-de-oro-en-madrid"
## [57] "https://www.tomaticket.es//es-es/entradas-gente-encerrada-en-sitios-en-madrid"
## [58] "https://www.tomaticket.es//es-es/entradas-ultrashow-en-barcelona"
## [59] "https://www.tomaticket.es//es-es/entradas-el-credito-en-madrid"
## [60] "https://www.tomaticket.es//es-es/entradas-rober-bodegas-en-madrid"
## [61] "https://www.tomaticket.es//es-es/entradas-improv-sololosvalientes-en-malaga"
## [62] "https://www.tomaticket.es//es-es/entradas-jamming-sessions-y-jamming-sessions-golfa-en-madrid"
## [63] "https://www.tomaticket.es//es-es/entradas-no-me-toques-el-cuento-en-madrid"
## [64] "https://www.tomaticket.es//es-es/entradas-ya-me-has-tocado-el-cuento-en-madrid"
## [65] "https://www.tomaticket.es//es-es/entradas-buenrollistas-en-barcelona"
## [66] "https://www.tomaticket.es//es-es/entradas-la-vida-regulinchi-daniel-fez-en-madrid"
## [67] "https://www.tomaticket.es//es-es/entradas-de-caperucita-a-loba-en-solo-seis-tios-en-madrid"
## [68] "https://www.tomaticket.es//es-es/entradas-improv-sololosvalientes-en-granada"
## [69] "https://www.tomaticket.es//es-es/entradas-el-brujo-lazarillo-de-tormes-madrid"
## [70] "https://www.tomaticket.es//es-es/entradas-desencantadas-en-madrid"
## [71] "https://www.tomaticket.es//es-es/entradas-joe-monty-magia-y-humor-muy-de-cerca-en-madrid"
## [72] "https://www.tomaticket.es//es-es/entradas-el-pequeno-conejo-blanco-en-madrid"
## [73] "https://www.tomaticket.es//es-es/entradas-los-gilipollas-en-madrid"
## [74] "https://www.tomaticket.es//es-es/entradas-corta-cable-rojo-barcelona"
## [75] "https://www.tomaticket.es//es-es/entradas-el-pequeno-mozart-en-madrid"
## [76] "https://www.tomaticket.es//es-es/entradas-andreu-casanova-en-barcelona"
## [77] "https://www.tomaticket.es//es-es/entradas-mitos-nordicos-madrid"
## [78] "https://www.tomaticket.es//es-es/entradas-lgtb-comedy-jam-en-madrid"
## [79] "https://www.tomaticket.es//es-es/entradas-shakespeare-en-madrid"
## [80] "https://www.tomaticket.es//es-es/entradas-espectaculo-de-flamenco-con-copa-en-madrid"
## [81] "https://www.tomaticket.es//es-es/entradas-hostia-patxi-en-barcelona"
## [82] "https://www.tomaticket.es//es-es/entradas-la-flauta-magica-en-madrid"
## [83] "https://www.tomaticket.es//es-es/entradas-bodas-de-sangre-en-madrid"
## [84] "https://www.tomaticket.es//es-es/entradas-hernani-en-madrid"
## [85] "https://www.tomaticket.es//es-es/entradas-luis-piedrahita-en-madrid"
## [86] "https://www.tomaticket.es//es-es/entradas-el-gato-con-botas-madrid"
## [87] "https://www.tomaticket.es//es-es/entradas-romancero-gitano-en-madrid"
## [88] "https://www.tomaticket.es//es-es/entradas-jaque-a-lo-imposible-magia-de-cerca-magia-y-humor-en-madrid"
## [89] "https://www.tomaticket.es//es-es/entradas-hipnonautas-en-madrid"
## [90] "https://www.tomaticket.es//es-es/entradas-srbohigues-leminencia-en-barcelona"
## [91] "https://www.tomaticket.es//es-es/entradas-sueno-de-una-noche-de-verano-madrid"
## [92] "https://www.tomaticket.es//es-es/entradas-tejido-conectivo-danza-en-la-sala-en-madrid"
## [93] "https://www.tomaticket.es//es-es/entradas-con-ganas-de-reir-madrid"
## [94] "https://www.tomaticket.es//es-es/entradas-katarsis-on-tour-en-madrid"
## [95] "https://www.tomaticket.es//es-es/entradas-callas-en-concierto-en-holograma-en-madrid"
## [96] "https://www.tomaticket.es//es-es/entradas-faemino-y-cansado-en-madrid"
## [97] "https://www.tomaticket.es//es-es/entradas-un-show-de-magia-pero-mas-chulo-en-madrid"
## [98] "https://www.tomaticket.es//es-es/entradas-la-troupe-comedy-monologos-en-barcelona"
## [99] "https://www.tomaticket.es//es-es/entradas-la-katarsis-del-tomatazo-en-madrid"
## [100] "https://www.tomaticket.es//es-es/entradas-pablo-corner-13-actos-magicos-211-en-madrid"
theaters <- c()
for (link in show_links) {
event_page <- read_html(link)
theater <- event_page %>%
html_node(xpath = "//div[@id='EventHeadContenido' and @class='white-space']//p[@class='nombre-recinto']//a") %>%
html_attr("href")
theaters <- c(theaters, theater)
}
theaters
## [1] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [2] "https://www.tomaticket.es/es-es/recintos/teatre-condal-barcelona"
## [3] "https://www.tomaticket.es/es-es/recintos/teatro-encantado-madrid"
## [4] "https://www.tomaticket.es/es-es/recintos/pequeno-teatro-gran-via-madrid"
## [5] "https://www.tomaticket.es/es-es/recintos/off-latina"
## [6] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [7] "https://www.tomaticket.es/es-es/recintos/gran-teatro-caixabank-principe-pio-madrid"
## [8] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [9] "https://www.tomaticket.es/es-es/recintos/teatro-capitol-madrid"
## [10] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [11] "https://www.tomaticket.es/es-es/recintos/teatro-figaro-madrid"
## [12] "https://www.tomaticket.es/es-es/recintos/cincomonos-espai-d-art"
## [13] "https://www.tomaticket.es/es-es/recintos/teatro-la-latina-madrid"
## [14] "https://www.tomaticket.es/es-es/recintos/cinesa-fuencarral-madrid"
## [15] "https://www.tomaticket.es/es-es/recintos/teatro-la-latina-madrid"
## [16] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [17] "https://www.tomaticket.es/es-es/recintos/teatro-zorrilla-valladolid"
## [18] "https://www.tomaticket.es/es-es/recintos/sala-pangoli"
## [19] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [20] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [21] "https://www.tomaticket.es/es-es/recintos/teatro-infanta-isabel-madrid"
## [22] "https://www.tomaticket.es/es-es/recintos/cincomonos-espai-d-art"
## [23] "https://www.tomaticket.es/es-es/recintos/la-villarroel-barcelona"
## [24] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [25] "https://www.tomaticket.es/es-es/recintos/teatro-infanta-isabel-madrid"
## [26] "https://www.tomaticket.es/es-es/recintos/gran-teatro-caixabank-principe-pio-madrid"
## [27] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [28] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [29] "https://www.tomaticket.es/es-es/recintos/safe-house"
## [30] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [31] "https://www.tomaticket.es/es-es/recintos/off-latina"
## [32] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [33] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [34] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [35] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [36] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [37] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [38] "https://www.tomaticket.es/es-es/recintos/pequeno-teatro-gran-via-madrid"
## [39] "https://www.tomaticket.es/es-es/recintos/off-latina"
## [40] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [41] "https://www.tomaticket.es/es-es/recintos/off-latina"
## [42] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [43] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [44] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [45] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [46] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [47] "https://www.tomaticket.es/es-es/recintos/sala-houdini-madrid"
## [48] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [49] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [50] "https://www.tomaticket.es/es-es/recintos/mun-coworking"
## [51] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [52] "https://www.tomaticket.es/es-es/recintos/teatro-alcazar-madrid"
## [53] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [54] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [55] "https://www.tomaticket.es/es-es/recintos/teatro-marquina"
## [56] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [57] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [58] "https://www.tomaticket.es/es-es/recintos/Teatre-Goya"
## [59] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [60] "https://www.tomaticket.es/es-es/recintos/pequeno-teatro-gran-via-madrid"
## [61] "https://www.tomaticket.es/es-es/recintos/la-cochera-cabaret-malaga"
## [62] "https://www.tomaticket.es/es-es/recintos/teatro-maravillas-madrid"
## [63] "https://www.tomaticket.es/es-es/recintos/teatro-pavon"
## [64] "https://www.tomaticket.es/es-es/recintos/teatros-luchana-madrid"
## [65] "https://www.tomaticket.es/es-es/recintos/Teatre-Goya"
## [66] "https://www.tomaticket.es/es-es/recintos/teatro-alcazar-madrid"
## [67] "https://www.tomaticket.es/es-es/recintos/pequeno-teatro-gran-via-madrid"
## [68] "https://www.tomaticket.es/es-es/recintos/teatro-municipal-del-zaidin-Isidro-Olgoso"
## [69] "https://www.tomaticket.es/es-es/recintos/teatro-alcazar-madrid"
## [70] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [71] "https://www.tomaticket.es/es-es/recintos/sala-houdini-madrid"
## [72] "https://www.tomaticket.es/es-es/recintos/teatro-sanpol"
## [73] "https://www.tomaticket.es/es-es/recintos/wit-comedy-club-madrid"
## [74] "https://www.tomaticket.es/es-es/recintos/teatre-apolo-barcelona"
## [75] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [76] "https://www.tomaticket.es/es-es/recintos/teatre-condal-barcelona"
## [77] "https://www.tomaticket.es/es-es/recintos/off-latina"
## [78] "https://www.tomaticket.es/es-es/recintos/iIntruso-bar-madrid"
## [79] "https://www.tomaticket.es/es-es/recintos/teatro-marquina"
## [80] "https://www.tomaticket.com/es-fr/recintos/taberna-flamenca-el-cortijo-madrid"
## [81] "https://www.tomaticket.es/es-es/recintos/la-sala-lastcrit-comedy-club"
## [82] "https://www.tomaticket.es/es-es/recintos/teatro-bellas-artes-madrid"
## [83] "https://www.tomaticket.es/es-es/recintos/SOJO-Laboratorio-Teatral"
## [84] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [85] "https://www.tomaticket.es/es-es/recintos/teatro-reina-victoria-madrid"
## [86] "https://www.tomaticket.es/es-es/recintos/teatro-lara-madrid"
## [87] "https://www.tomaticket.es/es-es/recintos/sala-torpedo-ciudad-real"
## [88] "https://www.tomaticket.es/es-es/recintos/sala-houdini-madrid"
## [89] "https://www.tomaticket.es/es-es/recintos/teatro-maravillas-madrid"
## [90] "https://www.tomaticket.es/es-es/recintos/Teatre-Goya"
## [91] "https://www.tomaticket.es/es-es/recintos/teatro-reina-victoria-madrid"
## [92] "https://www.tomaticket.es/es-es/recintos/la-sala-sevilla"
## [93] "https://www.tomaticket.es/es-es/recintos/teatro-arlequin"
## [94] "https://www.tomaticket.es/es-es/recintos/centro-de-nuevos-creadores-sala-mirador-madrid"
## [95] "https://www.tomaticket.es/es-es/recintos/gran-teatro-caixabank-principe-pio-madrid"
## [96] "https://www.tomaticket.es/es-es/recintos/teatro-capitol-madrid"
## [97] "https://www.tomaticket.es/es-es/recintos/teatro-victoria-3-madrid"
## [98] "https://www.tomaticket.es/es-es/recintos/trompo-karaoke-bar"
## [99] "https://www.tomaticket.es/es-es/recintos/centro-de-nuevos-creadores-sala-mirador-madrid"
## [100] "https://www.tomaticket.es/es-es/recintos/estupenda-cafe-bar"
coordenadas <- c()
for (link in show_links) {
event_page <- read_html(link)
localizacion <- event_page %>%
html_node(xpath = "//a[contains(@class, 'sidebar-links') and contains(@href, 'maps.google.com')]/@href") %>%
html_text()
coordenadas <- c(coordenadas,localizacion)
}
df_coordenadas <- data.frame(coordenada = coordenadas)
df_coordenadas$coordenada <- sub(".*/?q=(.*)$", "\\1", df_coordenadas$coordenada)
df_1 <- as_tibble(df_coordenadas)
df_1<- separate(df_1, coordenada, into = c("Latitud", "Longitud"), sep = ",")
df_1$id <- c(1:100)
coordenadas
## [1] NA
## [2] "https://maps.google.com/?q=41.3749,2.16526"
## [3] "https://maps.google.com/?q=40.3985,-3.7039"
## [4] "https://maps.google.com/?q=40.422416,-3.7089372"
## [5] "https://maps.google.com/?q=40.412667,-3.71208"
## [6] "https://maps.google.com/?q=40.42147,-3.70853"
## [7] "https://maps.google.com/?q=40.421075,-3.718859"
## [8] "https://maps.google.com/?q=40.42147,-3.70853"
## [9] "https://maps.google.com/?q=40.420692,-3.706614"
## [10] "https://maps.google.com/?q=40.42241,-3.704353"
## [11] "https://maps.google.com/?q=40.413488,-3.703703"
## [12] NA
## [13] "https://maps.google.com/?q=40.4113,-3.70874"
## [14] NA
## [15] "https://maps.google.com/?q=40.4113,-3.70874"
## [16] "https://maps.google.com/?q=40.42147,-3.70853"
## [17] "https://maps.google.com/?q=41.6522,-4.72866"
## [18] NA
## [19] "https://maps.google.com/?q=40.42241,-3.704353"
## [20] "https://maps.google.com/?q=40.42147,-3.70853"
## [21] "https://maps.google.com/?q=40.422231,-3.695507"
## [22] NA
## [23] NA
## [24] "https://maps.google.com/?q=40.42241,-3.704353"
## [25] "https://maps.google.com/?q=40.422231,-3.695507"
## [26] "https://maps.google.com/?q=40.421075,-3.718859"
## [27] "https://maps.google.com/?q=40.42241,-3.704353"
## [28] NA
## [29] NA
## [30] "https://maps.google.com/?q=40.42241,-3.704353"
## [31] "https://maps.google.com/?q=40.412667,-3.71208"
## [32] NA
## [33] NA
## [34] NA
## [35] NA
## [36] NA
## [37] NA
## [38] "https://maps.google.com/?q=40.422416,-3.7089372"
## [39] "https://maps.google.com/?q=40.412667,-3.71208"
## [40] NA
## [41] "https://maps.google.com/?q=40.412667,-3.71208"
## [42] NA
## [43] NA
## [44] NA
## [45] NA
## [46] NA
## [47] NA
## [48] NA
## [49] "https://maps.google.com/?q=40.42241,-3.704353"
## [50] NA
## [51] "https://maps.google.com/?q=40.42147,-3.70853"
## [52] "https://maps.google.com/?q=40.417757,-3.699082"
## [53] NA
## [54] "https://maps.google.com/?q=40.42241,-3.704353"
## [55] "https://maps.google.com/?q=40.422652,-3.693642"
## [56] "https://maps.google.com/?q=40.42147,-3.70853"
## [57] "https://maps.google.com/?q=40.42241,-3.704353"
## [58] NA
## [59] "https://maps.google.com/?q=40.42147,-3.70853"
## [60] "https://maps.google.com/?q=40.422416,-3.7089372"
## [61] "https://maps.google.com/?q=36.6913,-4.44846"
## [62] "https://maps.google.com/?q=40.42885,-3.703235"
## [63] NA
## [64] NA
## [65] NA
## [66] "https://maps.google.com/?q=40.417757,-3.699082"
## [67] "https://maps.google.com/?q=40.422416,-3.7089372"
## [68] NA
## [69] "https://maps.google.com/?q=40.417757,-3.699082"
## [70] "https://maps.google.com/?q=40.42241,-3.704353"
## [71] NA
## [72] NA
## [73] NA
## [74] "https://maps.google.com/?q=41.3749,2.17048"
## [75] "https://maps.google.com/?q=40.42241,-3.704353"
## [76] "https://maps.google.com/?q=41.3749,2.16526"
## [77] "https://maps.google.com/?q=40.412667,-3.71208"
## [78] NA
## [79] "https://maps.google.com/?q=40.422652,-3.693642"
## [80] "https://maps.google.com/?q=40.3955,-3.66178"
## [81] NA
## [82] "https://maps.google.com/?q=40.418488,-3.696378"
## [83] NA
## [84] "https://maps.google.com/?q=40.42147,-3.70853"
## [85] "https://maps.google.com/?q=40.4166,-3.69953"
## [86] "https://maps.google.com/?q=40.42241,-3.704353"
## [87] "https://maps.google.com/?q=39.0328,-4.17565"
## [88] NA
## [89] "https://maps.google.com/?q=40.42885,-3.703235"
## [90] NA
## [91] "https://maps.google.com/?q=40.4166,-3.69953"
## [92] NA
## [93] "https://maps.google.com/?q=40.42147,-3.70853"
## [94] "https://maps.google.com/?q=40.407,-3.69885"
## [95] "https://maps.google.com/?q=40.421075,-3.718859"
## [96] "https://maps.google.com/?q=40.420692,-3.706614"
## [97] "https://maps.google.com/?q=40.4237,-3.70548"
## [98] NA
## [99] "https://maps.google.com/?q=40.407,-3.69885"
## [100] NA
only_prices <- tomaticket %>%
xml_find_all("//p[@class='bottommargin-precio' and @itemprop='offers' and @itemscope='' and @itemtype='https://schema.org/AggregateOffer']//meta[@itemprop='price']")
only_prices
## {xml_nodeset (100)}
## [1] <meta itemprop="price" content="18,00">
## [2] <meta itemprop="price" content="17,00">
## [3] <meta itemprop="price" content="15">
## [4] <meta itemprop="price" content="20,00">
## [5] <meta itemprop="price" content="6,50">
## [6] <meta itemprop="price" content="12,00">
## [7] <meta itemprop="price" content="20,00">
## [8] <meta itemprop="price" content="14,00">
## [9] <meta itemprop="price" content="16,00">
## [10] <meta itemprop="price" content="14,00">
## [11] <meta itemprop="price" content="16,00">
## [12] <meta itemprop="price" content="15">
## [13] <meta itemprop="price" content="16,00">
## [14] <meta itemprop="price" content="16,00">
## [15] <meta itemprop="price" content="16,00">
## [16] <meta itemprop="price" content="12,00">
## [17] <meta itemprop="price" content="22">
## [18] <meta itemprop="price" content="15">
## [19] <meta itemprop="price" content="18,00">
## [20] <meta itemprop="price" content="15,00">
## ...
datetime <- tomaticket %>%
xml_find_all("//p[@class='bottommargin-precio' and @itemprop='offers' and @itemscope='' and @itemtype='https://schema.org/AggregateOffer']//time")
datetime
## {xml_nodeset (100)}
## [1] <time itemprop="validFrom" datetime="2021-05-07 19:30:00"></time>
## [2] <time itemprop="validFrom" datetime="2022-06-17 22:30:00"></time>
## [3] <time itemprop="validFrom" datetime="2022-08-27 21:00:00"></time>
## [4] <time itemprop="validFrom" datetime="2022-08-31 20:00:00"></time>
## [5] <time itemprop="validFrom" datetime="2022-09-03 20:00:00"></time>
## [6] <time itemprop="validFrom" datetime="2022-09-26 18:00:00"></time>
## [7] <time itemprop="validFrom" datetime="2022-10-08 19:00:00"></time>
## [8] <time itemprop="validFrom" datetime="2022-10-12 20:30:00"></time>
## [9] <time itemprop="validFrom" datetime="2022-10-22 22:00:00"></time>
## [10] <time itemprop="validFrom" datetime="2022-11-12 19:30:00"></time>
## [11] <time itemprop="validFrom" datetime="2023-01-01 20:30:00"></time>
## [12] <time itemprop="validFrom" datetime="2023-02-25 21:00:00"></time>
## [13] <time itemprop="validFrom" datetime="2023-02-27 21:00:00"></time>
## [14] <time itemprop="validFrom" datetime="2023-03-09 20:30:00"></time>
## [15] <time itemprop="validFrom" datetime="2023-03-13 18:00:00"></time>
## [16] <time itemprop="validFrom" datetime="2023-03-13 20:00:00"></time>
## [17] <time itemprop="validFrom" datetime="2023-03-30 20:30:00"></time>
## [18] <time itemprop="validFrom" datetime="2023-04-08 21:00:00"></time>
## [19] <time itemprop="validFrom" datetime="2023-04-30 12:00:00"></time>
## [20] <time itemprop="validFrom" datetime="2023-05-06 21:00:00"></time>
## ...
location <- tomaticket %>%
xml_find_all("//p[@class='lugar' and @itemprop='location' and @itemscope='' and @itemtype='https://schema.org/Place']//meta")
location
## {xml_nodeset (200)}
## [1] <meta itemprop="address" content="Madrid">
## [2] <meta itemprop="name" content="Madrid">
## [3] <meta itemprop="address" content="Barcelona">
## [4] <meta itemprop="name" content="Barcelona">
## [5] <meta itemprop="address" content="Madrid">
## [6] <meta itemprop="name" content="Madrid">
## [7] <meta itemprop="address" content="Madrid">
## [8] <meta itemprop="name" content="Madrid">
## [9] <meta itemprop="address" content="Madrid">
## [10] <meta itemprop="name" content="Madrid">
## [11] <meta itemprop="address" content="Madrid">
## [12] <meta itemprop="name" content="Madrid">
## [13] <meta itemprop="address" content="Madrid">
## [14] <meta itemprop="name" content="Madrid">
## [15] <meta itemprop="address" content="Madrid">
## [16] <meta itemprop="name" content="Madrid">
## [17] <meta itemprop="address" content="Madrid">
## [18] <meta itemprop="name" content="Madrid">
## [19] <meta itemprop="address" content="Madrid">
## [20] <meta itemprop="name" content="Madrid">
## ...
Creating the data frames
df_theaters <- data.frame(theater = theaters)
df_shows <- data.frame(show_links)
clean_dates <- sub("^[^=]+=[^=]+=(.*)$", "\\1", datetime)
clean_dates <- sub(".*\"(\\d{4}-\\d{2}-\\d{2}).*", "\\1", clean_dates)
dates <- as.Date(clean_dates)
df_date <- data.frame(dates)
df_date$id <- c(1:100)
df_theaters$theater_name <- sub(".*/recintos/(.*)$", "\\1", df_theaters$theater)
df_theaters <- df_theaters %>%
select(-theater)
df_theaters$id <- c(1:100)
final_df <- left_join(df_theaters, df_date, by = "id")
df_shows$show <- sub(".*/entradas-(.*)", "\\1", df_shows$show_links)
df_shows <- df_shows %>%
select(-show_links)
df_shows$id <- c(1:100)
final_df <- left_join(final_df, df_shows, by = "id")
location_address <- grep('address', location, value = TRUE)
clean_location <- sub('.*="([^"]*)".*', '\\1', location_address)
df_location <- data.frame(clean_location)
df_location$id <- c(1:100)
final_df <- left_join(final_df, df_location, by = "id")
clean_prices <- sub('.*="([^"]*)".*', '\\1', only_prices)
df_prices <- data.frame(clean_prices)
df_prices$id <- c(1:100)
df_prices$clean_prices <- gsub(",", ".", df_prices$clean_prices)
df_prices$clean_prices <- as.numeric(df_prices$clean_prices)
df_prices$clean_prices <- round(df_prices$clean_prices, 2)
final_df <- left_join(final_df, df_prices, by = "id")
final_df$show <- gsub("-", " ", final_df$show)
final_df$theater_name <- gsub("-", " ", final_df$theater_name)
current_date <- as.Date("2024-03-22", format = "%Y-%m-%d")
current_date <- rep(current_date, times = 100)
df_current_date <- data.frame(current_date)
df_current_date$id <- c(1:100)
final_df <- left_join(final_df, df_current_date, by = "id")
final_df <- final_df %>%
select(id, everything())
final_df <- final_df %>%
rename(location = clean_location, prices = clean_prices)
final_df <- final_df %>%
relocate(dates, .after = prices)
final_df <- final_df %>%
mutate(days_elapsed = difftime(current_date, dates))
final_df <- left_join(final_df, df_1, by = "id")
final_df$days_elapsed <- as.numeric(final_df$days_elapsed, units = "days")
Main issues
final_df <- read_csv("final_df.csv")
## Rows: 100 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): theater_name, show, location
## dbl (5): id, prices, days_elapsed, Latitud, Longitud
## date (2): dates, current_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
final_df <- final_df %>%
slice(-93, -98)
## # A tibble: 98 × 10
## id theater_name show location prices dates current_date days_elapsed
## <dbl> <chr> <chr> <chr> <dbl> <date> <date> <dbl>
## 1 1 teatros luc… dobl… Madrid 18 2021-05-07 2024-03-22 1050
## 2 2 teatre cond… yo s… Barcelo… 17 2022-06-17 2024-03-22 644
## 3 3 teatro enca… magi… Madrid 15 2022-08-27 2024-03-22 573
## 4 4 pequeno tea… cort… Madrid 20 2022-08-31 2024-03-22 569
## 5 5 off latina impo… Madrid 6.5 2022-09-03 2024-03-22 566
## 6 6 teatro arle… la m… Madrid 12 2022-09-26 2024-03-22 543
## 7 7 gran teatro… davi… Madrid 20 2022-10-08 2024-03-22 531
## 8 8 teatro arle… la a… Madrid 14 2022-10-12 2024-03-22 527
## 9 9 teatro capi… alex… Madrid 16 2022-10-22 2024-03-22 517
## 10 10 teatro figa… una … Madrid 16 2023-01-01 2024-03-22 446
## # ℹ 88 more rows
## # ℹ 2 more variables: Latitud <dbl>, Longitud <dbl>
Descriptive Analysis
- National Level

- Analyzing Madrid´s theaters

Let´s see the most expensive and the cheapest theaters in Madrid
data_madrid_tp <- data_madrid %>%
group_by(theater_name) %>%
summarise(avg_price = round(mean(prices, na.rm = TRUE), 2)) # 27 teatros diferentes
Most expensive theaters:
data_madrid_tp %>% slice_max(avg_price, n = 6)
## # A tibble: 6 × 2
## theater_name avg_price
## <chr> <dbl>
## 1 gran teatro caixabank principe pio madrid 21
## 2 teatro marquina 18.2
## 3 taberna flamenca el cortijo madrid 18
## 4 teatro alcazar madrid 17.5
## 5 teatro reina victoria madrid 17.5
## 6 pequeno teatro gran via madrid 16.5
Cheapest theaters:
data_madrid_tp %>% slice_min(avg_price, n = 6)
## # A tibble: 6 × 2
## theater_name avg_price
## <chr> <dbl>
## 1 iIntruso bar madrid 5
## 2 wit comedy club madrid 7
## 3 meltdown madrid 8
## 4 teatro bellas artes madrid 8
## 5 off latina 8.64
## 6 SOJO Laboratorio Teatral 11.0
Clustering
data_clustering <- teatros_con_mas_shows %>%
select(theater_name, prices, num_obras, days_elapsed)
data_clustering_norm <- data_clustering %>%
select(-theater_name) %>%
scale()
set.seed(123)
kmeans_model <- kmeans(data_clustering_norm, centers = 3)
teatros_con_mas_shows$cluster <- as.factor(kmeans_model$cluster)
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
## Too few points to calculate an ellipse